const http = require('http');
// const url = require("url");
 const fs = require("fs");
const server = http.createServer((request,response)=>{

    // response.setHeader('content-type','text/html;charset=utf-8');
   console.log(request.headers);
   
    let {pathname} = new URL(request.url,"http://127.0.0.1:9000"); 
    let newPath = __dirname+pathname;
    console.log(newPath);
    fs.readFile(newPath,(err,data)=>{
        if(err){response.end("返回错误");return;}console.log(data);
        response.end(data);
    }) 
})

server.listen(9000,()=>{
    console.log("服务启动成功...");
})